from django.conf import settings

from django.contrib import admin
from django.core.cache import caches

from goods.models import Catalog, SKU
GOODS_INDEX_CACHE=caches['goods_index']
GOODS_DETAIL_CACHE=caches[('goods_detail'
                           '')]
@admin.register(SKU)
class SKUAdmin(admin.ModelAdmin):
    def save_model(self, request, obj, form, change):
        super().save_model(request, obj, form, change)
        #首页缓存清除
        GOODS_INDEX_CACHE.clear()
        # 详情缓存清除
        key=f'gd{obj.id}'
        GOODS_DETAIL_CACHE.delete(key)
        print('商品首页缓存清除')
        print('商品详情页缓存清除')

    def delete_model(self, request, obj):
        super().delete_model(request, obj)
        #首页缓存清除
        GOODS_INDEX_CACHE.clear()
        # 详情缓存清除
        key = f'gd{obj.id}'
        GOODS_DETAIL_CACHE.delete(key)



